package com.ht.medicaltreatment.adapter

import android.widget.TextView
import com.blankj.utilcode.util.LogUtils
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.ht.medicaltreatment.R
import com.ht.medicaltreatment.bean.SampleLocationData

class SampleLocationAdapter:BaseQuickAdapter<SampleLocationData,BaseViewHolder>(R.layout.item_sample_location_layout) {

    //原始选择的id
    private var oId = -1
    //最新修改的id
    private var nId = -1

    private val l = arrayOf("A","B","C","D","E","F","G","H","I","J")

    fun setCheckId(oId:Int,nId:Int) {
        this.oId = oId
        this.nId = nId
        LogUtils.i("oId: $oId, nId: $nId")
    }

    override fun convert(holder: BaseViewHolder, item: SampleLocationData) {
        //val sign: Int,//0 未使用   1已经占用  2 借出

        val tvName = holder.getView<TextView>(R.id.tvName)
        if(item.id == oId){
            tvName.setBackgroundResource(R.drawable.shape_scan_item_orange_bg)
        }else if(item.id == nId){
            tvName.setBackgroundResource(R.drawable.shape_scan_item_green_bg)
        }else {
            if(item.sign == 1){
                tvName.setBackgroundResource(R.drawable.shape_scan_item_blue_bg)
            }else if(item.sign == 2){
                tvName.setBackgroundResource(R.drawable.shape_scan_item_yellow_bg)
            }else{
                tvName.setBackgroundResource(R.drawable.shape_scan_item_white_bg)
            }
        }
        when(item.sampleBoxStru.structureSpec){
            //"数字 * 数字"
            1 ->  holder.setText(R.id.tvName,"${item.row}/${item.col}")
            //"数字 * 字母"
            2 ->  holder.setText(R.id.tvName,"${item.row}/${l[getItemPosition(item)%9]}")
            //"字母 * 数字"
            3 ->  holder.setText(R.id.tvName,"${l[item.row]}/${item.col}")
            // "字母 * 字母"
            4 ->  holder.setText(R.id.tvName,"${l[item.row]}/${l[getItemPosition(item)%9]}")
            //"内部数字"
            5 ->  holder.setText(R.id.tvName,"${getItemPosition(item)+1}")
        }
    }
}
